package af.Action;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.actions.DispatchAction;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;

import af.Class.Activo;
import af.Form.ActivoForm;


public class ActivoAction extends DispatchAction{

	public ActionForward ListaActivos(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
		Activo activo = new Activo();
        //HttpSession session = request.getSession();
			
        request.getSession().setAttribute("grActivo", activo.ListaActivo());
        

        return mapping.findForward("listar");
    }

	public ActionForward NuevoActivos(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
		ActivoForm frm = (ActivoForm) form;
		
		Activo activo = new Activo();
		
		request.setAttribute( "respCombo", activo.RespCombo());
        request.setAttribute( "ubiCombo", activo.UbiCombo());
        request.setAttribute( "nivCombo", activo.nivCombo());
        
		frm.setNuevo("S");
		return mapping.findForward("nuevo");
	}
	public ActionForward ModificarActivo(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
		
			String cod = request.getParameter("idActivo");
			Activo activo = new Activo();
			
			request.setAttribute( "respCombo", activo.RespCombo());
	        request.setAttribute( "ubiCombo", activo.UbiCombo());
	        request.setAttribute( "nivCombo", activo.nivCombo());
			
			ActivoForm frm = (ActivoForm) form;
			frm.setNuevo("M");
			frm.setIdActivo(cod);
			frm = activo.TraeActivo(frm);
						
		return mapping.findForward("modificar");
	}
	
	public ActionForward EliminarActivo(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
		
			String cod = request.getParameter("idActivo");
			Activo activo = new Activo();
			ActivoForm frm = (ActivoForm) form;
			frm.setIdActivo(cod);
			
			activo.EliminaActivo(frm);
				
						
			return mapping.findForward("eliminar");
	}
	
}



